package yunc.checkData.pojo;

import java.util.HashMap;
import java.util.List;

public class TideData {
    private HashMap<String,Integer> data;

    public TideData() {
    }

    public TideData(TitleTide title, List<String> data) {
        HashMap<String,Integer> dataMap = new HashMap<>();
        this.data = dataMap;
    }

    public String getDateFromIndex(String month,String str,int indexAt){

        String day = str.substring(2, 4);
        String hour = str.substring(4, 6);
        String minuteMark = str.substring(6, 7);
        Integer minute = (Integer.parseInt(minuteMark)-1)*12+indexAt;
        String minuteStr = minute.toString();
        if (minuteStr.length()!=2) {
            minuteStr="0"+ minuteStr;
        }
        return month + "-" + day + " " + hour + ":" + minuteStr + ":00";
    }

    public HashMap<String,Integer> getDataListFromstr(String month, String str, int dataStartAt,int dataLength, int dataNum){
        HashMap<String,Integer> datas = new HashMap<>();

        try{
            for (int i = 0; i < dataNum; i++) {
                int start = dataStartAt + (dataLength * i);
                int end = dataStartAt + (dataLength * (i + 1));
                if (end > str.length()) {
                    end=str.length();
                }
                String data = str.substring(start, end);
                String date = getDateFromIndex(month,str,i);
                datas.put(date,Integer.parseInt(data.replace(" ","")));
            }
        }catch(Exception e){
            System.out.println(str);
            e.printStackTrace();
            System.exit(1);
        }


        return datas;
    }
}
